<?php

/**
 * Created by PhpStorm.
 * User: ls721
 * Date: 2016/10/28 0028
 * Time: 21:35
 */
class Domain_Comment
{

    public function setComment($comment_id, $event_id, $doctor_id, $content, $record)
    {
        $model = new Model_Comment();
        $Cid = uniqid("C");
        if (empty($comment_id)) {
            $rse = $model->isExist($event_id, $doctor_id);
            if (empty($rse)) {
                $model->insert(array(
                    'id' => $Cid,
                    'Event_id' => $event_id,
                    'Doctor_id' => $doctor_id,
                    'Content' => $content,
                    'Record' => $record
                ));
                return $model->getComment($Cid);
            } else {
                $Cid = $rse["id"];
                $model->update($Cid, array(
                    'Event_id' => $event_id,
                    'Doctor_id' => $doctor_id,
                    'Content' => $content,
                    'Record' => $record
                ));
                return $model->getComment($Cid);
            }
        } else {
            $model->update($comment_id, array(
                'Event_id' => $event_id,
                'Doctor_id' => $doctor_id,
                'Content' => $content,
                'Record' => $record
            ));
            return $model->getComment($comment_id);
        }


    }

    public function setCommentImage($comment_id, $image)
    {
        $model = new Model_Image();
        DI()->ucloud->set('default_path', 'comment');
        DI()->ucloud->set('save_path', date('Y/m/d'));

        //新增修改文件名设置上传的文件名称
        $Iid = uniqid("I");

        DI()->ucloud->set('file_name', $Iid);

        //上传表单名
        $rs = DI()->ucloud->upfile($image);
        $model->insert(array('Comment_Id' => $comment_id, 'Image_id' => $Iid, 'image' => $rs['url']));
        return $model->getImagesOfComment($comment_id);


    }

    public function listComment($doctor_id, $event_id)
    {
        $model = new Model_Comment();
        return $model->listComment($doctor_id, $event_id);
    }
    public function listRecord( $event_id)
    {
        $model = new Model_Comment();
        return $model->listRecord( $event_id);
    }

    public function getComment($comment_id)
    {
        $model = new Model_Comment();
        $rs1 = $model->getComment($comment_id);
        $model_Event = new Model_Event();
        $rs2 = $model_Event->getEventInfo($rs1["EventId"]);
        return array_merge($rs2, $rs1);

    }

}